package 招聘.滴滴;

import java.util.Collections;
import java.util.Comparator;
import java.util.Scanner;
import java.util.Vector;

public class Main {
    public static void main(String[] args) {
        int n, Total, Cost;
        Scanner s = new Scanner(System.in);
        n = s.nextInt();
        Total = s.nextInt();
        Cost = s.nextInt();
        Vector<Integer> A = new Vector<>();
        Vector<Integer> B = new Vector<>();
        Vector<Integer> MarkDownAPositionInB = new Vector<>(n);
        int Count = 0;
        for (int i = 0; i < n; i++) {
            MarkDownAPositionInB.add(0);
        }
        for (int i = 0; i < n; i++) {
            A.add(s.nextInt());
        }
        for (int i = 0; i < n; i++) {
            B.add(s.nextInt());
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (B.get(j).equals(A.get(i))) {
                    MarkDownAPositionInB.set(i, j);

                }
            }
        }

        Total -= n - MarkDownAPositionInB.get(n - 1) + 1;
        int move = Total % Cost;

        if (move >= MarkDownAPositionInB.get(n - 1) + 1)
            System.out.println(MarkDownAPositionInB.get(n - 1) + 1);
        else System.out.println(move);

    }
}